using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using ShoppingCenter.Backend.Api.Db;
using ShoppingCenter.Backend.Api.Model;
using ShoppingCenter.Backend.Api.Params;
using ShoppingCenter.Backend.Api.Repository;
using ShoppingCenter.Backend.Api.Utils;

namespace ShoppingCenter.Backend.Api.Controllers
{
    [Authorize]
    [ApiController]
    [Route("[controller]")]

    //供应商控制器
    public class SupplierController : ControllerBase
    {
        private IConfiguration _configuration;

        private IRepository<Supplier> _supplierRepository;

        public SupplierController(IConfiguration configuration, IRepository<Supplier> supplierRepository)
        {
            _configuration = configuration;
            _supplierRepository = supplierRepository;
        }



        //获取所有供应商
        public dynamic Get()
        {
            var currentPage = int.Parse(Request.Query["currentPage"][0]);
            var pageSize = int.Parse(Request.Query["pageSize"][0]);

            var shopingDb = new ShoppingCenterDb();

            // 分页
            var suppliers = shopingDb.Supplier.Include(x => x.Merchant).ToList().Skip((currentPage - 1) * pageSize).Take(pageSize); ;

            return new
            {
                Code = 1000,
                 Data = new
                {
                    Data = suppliers,
                    Pager = new { currentPage, pageSize, totalSize = suppliers.Count() }
                },
                Msg = "获取所有供应商成功"
            };
        }
    }
}